var app = getApp()
module.exports = {
  request
}
const baseUrl = "http://127.0.0.1"

let ajaxTimes = 0; // 处理数据请求的总数，用来控制loading图标

/** 
 * 处理数据请求的接口
 */
function request(params) {
  ajaxTimes++
  wx.showLoading({
    title: '加载中',
    mask: true
  })
  return new Promise((resolve, reject) => {
    wx.request({
      ...params,
      url: baseUrl + params.url,
      dataType: 'json',
      header: {
        "accept": "*/*",
        "conent-type": "application/json",
        "Cookie": "connect.sid=o_AjJ5d9H24PmSMU5T6rU5cph-3o"
      },
      success: (result) => {
        resolve(result.data)
      },
      fail: (err) => {
        console.log(err)
        reject(err)
      },
      complete: () => {
        ajaxTimes--
        if (ajaxTimes === 0) {
          wx.hideLoading()
        }
      }
    })
  })
}